package application.client.gui.components;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;

import application.controller.client.GuiController;

import middleware.datacontainer.groupPropertiesChange.GroupPropertiesContainer;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class SettingTab extends JPanel{
		
	private HashMap<GroupPropertiesContainer, GroupSettingPanel> groups = new HashMap<GroupPropertiesContainer,GroupSettingPanel>();
	private JPanel groupSettingPanel;
	private JButton saveButton;
	public SettingTab()
	{
		super(true);
		init();
	}
	private void init()
	{
		this.setLayout(new BorderLayout());
		this.setBackground(new java.awt.Color(255,255,255));
		
		groupSettingPanel = new JPanel();
		this.add(groupSettingPanel, BorderLayout.NORTH);
		groupSettingPanel.setLayout(new FlowLayout());
		groupSettingPanel.setPreferredSize(new java.awt.Dimension(10, 315));
		groupSettingPanel.setBackground(new java.awt.Color(255,255,255));
		
		
		JPanel buttonPanel = new JPanel();
		saveButton=new JButton("Save");
		buttonPanel.setLayout(new BorderLayout());
		buttonPanel.add(saveButton,BorderLayout.EAST);
		buttonPanel.setBackground(Color.white);
		saveButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				List<GroupPropertiesContainer> list=new ArrayList<GroupPropertiesContainer>();
				for (GroupSettingPanel gSP : groups.values()) {
					
					list.add(gSP.getAttributes());
				}
				GuiController.getInstance().saveGroupProperties(list);
				
			}
		});
		
		this.add(buttonPanel,BorderLayout.CENTER);
		
		JPanel dummyPanelR = new JPanel();
		add(dummyPanelR, BorderLayout.EAST);
		dummyPanelR.setBackground(new java.awt.Color(255,255,255));
		dummyPanelR.setPreferredSize(new java.awt.Dimension(17, 380));
		this.add(new ImagePanel(), BorderLayout.SOUTH);
	}
	
	public void setGroupProperties(List<GroupPropertiesContainer> gPC)
	{
		
		for (GroupPropertiesContainer groupPropertiesContainer : gPC) {
			GroupSettingPanel g = new GroupSettingPanel();
			groups.put(groupPropertiesContainer, g);
			
			g.setGroupAttributes(groupPropertiesContainer);
			groupSettingPanel.add(g);
			setSaveButton();
		}
	}
	private void setSaveButton()
	{
		
	}
	
}
